<?php

namespace App\Http\Controllers\api;


use App\factory\Factory;
use App\Http\Controllers\Controller;
use App\Http\Service\api\AliPay;
use Illuminate\Http\Request;
class PaymentApiController extends Controller
{
    /**
     * @param Request $request
     * 支付
     */
    public function pay(Request $request){
        try {
            $data = $request->input();
            Factory::factoryPay($data);
            return ['200','支付成功',''];
        }catch (\Exception $exception){
            return ['2001',$exception->getMessage(),''];
        }
    }

    /**
     * @throws \Yansongda\Pay\Exceptions\InvalidConfigException
     * @throws \Yansongda\Pay\Exceptions\InvalidSignException
     * 支付成功回调参数
     *  订单号：$data->out_trade_no
     * 支付宝交易号：$data->trade_no
     * 订单总金额：$data->total_amount
     */
    public function aliPaySuccess()
    {
        try{
            $res = new AliPay();
            $data =$res->paySuccess();
            return  $data;
        }catch (\Exception $exception){
            return ['2001',$exception->getMessage(),''];
        }
    }

    /**
     * @return array
     * 提现
     */
    public function extract(Request $request){
        try{
            $data = $request->input();
             Factory::extract($data);
        }catch (\Exception $exception){
            return ['2001',$exception->getMessage(),''];
        }
    }


}
